//
//  APIResult.swift
//  
//
//  Created by tank on 2021/10/15.
//

import Foundation


public struct APIResult<T> {
    public var code: Int
    
    public var message: String?
    
    public var data: T?
    
    public init(code: Int, message: String?, data: T?) {
        
        self.code = code
        
        self.message = message
        
        self.data = data
    }
    
    public func isSuccess() -> Bool {
        return code == HttpService.successCode
    }
}

extension APIResult: Codable where T: Codable {
    enum CodingKeys: String, CodingKey {
        case code
        case message = "msg"
        case data
    }
}
